import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index.vue'

Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    hidden: true,
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/',
    redirect: '/platform',
    needRoot: true, // children为1个时, 子路由显示为根路由
    name: 'Platform',
    component: Layout,
    children: [
      {
        path: 'platform',
        name: 'platform',
        component: () => import('@/views/platform/index'),
        meta: { title: '游戏平台列表', icon: '#icon-NAVqukuailian', roles: [1, 2, 3] }
      }
    ]
  },
  {
    path: '/404',
    name: 'error',
    hidden: true,
    component: () => import('../views/error/index.vue')
  }
]

export const asyncRoutes = [
  {
    path: '/game',
    redirect: '/game/gold',
    component: Layout,
    meta: { title: '游戏模块', icon: '#icon-MailChimp', roles: [1, 2, 3] },
    children: [
      {
        path: 'gold',
        name: 'gold',
        component: () => import('../views/game/gold/index'),
        meta: { title: '金币场', icon: '#icon-jiemianru', roles: [1, 2] }
      },
      {
        path: '/entertainConf',
        name: 'entertainConf',
        component: () => import('../views/game/entertainConf/index'),
        meta: { title: '娱乐场', icon: '#icon-shengle', roles: [1, 2] }
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/sign',
    meta: { title: '运营活动', icon: '#icon-Figma', roles: [1, 2, 3] },
    children: [
      {
        path: 'sign',
        component: () => import('../views/activity/sign/index'),
        meta: { title: '签到活动', icon: '#icon-lvyou', roles: [1, 2, 3] }
      },
      {
        path: 'rank',
        component: () => import('../views/activity/rank/index'),
        meta: { title: '排行活动', icon: '#icon-beizichajushui', roles: [1, 2, 3] }
      }
    ]
  }
]

const createRouter = () => new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
